{% macro error(attr) %}
{% if attr.errors %}
{% for error in attr.errors %}
<div class="text-danger">{{ error }}</div>
{% endfor %}
{% endif %}
{% endmacro %}

{% macro render(attr) %}
<div class="form-group has-feedback {{ 'has-error' if attr.errors }}">
    {% if attr.type == 'StringField' or attr.type == 'PasswordField' %}
        {{ attr(class='form-control ' ~ kwargs.class, placeholder=attr.label.text) }}
        {% if kwargs.icon %}
            <span class="glyphicon {{ kwargs.icon }} form-control-feedback"></span>
        {% endif %}
        {{ error(attr) }}
    {% elif attr.type == 'SubmitField' %}
        {{ attr(class='btn btn-primary btn-flat ' ~ kwargs.class) }}
        {{ error(attr) }}
    {% elif attr.type == 'SelectField' %}
        {{ attr(class="form-control select2 select2-hidden-accessible "~kwargs.class) }}
        {{ error(attr) }}
    {% else %}
        {{ attr() }}
        {{ error(attr) }}
    {% endif %}
</div>
{% endmacro %}

{% macro render_edit(attr) %}
<div class="form-group {{ 'has-error' if attr.errors }}">
    <label class="col-sm-2 control-label">{{ attr.label.text }}</label>

    <div class="col-sm-10">
        {% if attr.type == 'StringField' or attr.type == 'PasswordField' %}
            {{ attr(class='form-control ' ~ kwargs.class, placeholder=attr.label.text) }}
            {{ error(attr) }}
        {% elif attr.type == 'SelectField' %}
            {{ attr(class="form-control select2 select2-hidden-accessible "~kwargs.class) }}
            {{ error(attr) }}
        {% else %}
            {{ attr() }}
            {{ error(attr) }}
        {% endif %}
    </div>
</div>
{% endmacro %}
